<template>
   
  <div class="order">
    <headcamp :back="$route.meta.back" :title="$route.meta.title"></headcamp>

    <div class="box">
      <!-- //新增地址 -->
      <van-address-list 
       v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        @add="onAdd"
       @select="change"
      />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      uid: this.$utils.getuid(),
      list: [],
     chosenAddressId: '1',
    };
  },
  methods: {
    fn() {
      this.$api.addresslist({ uid: this.uid }).then((res) => {
        console.log(res);
        this.list = res.data.list.map((item) => {
          return {
            id: item.id,
            name: item.username,
            tel: item.userphone,
            address: item.location+item.useraddress,
            isDefault: item.status ? 1:2,
          };
        });
      });
    },
    //跳转到新增地址页面
    onAdd(){
      this.$router.push('/address')
    },
   change(val){
      console.log(val);
      this.$router.push('/order?addreslist='+JSON.stringify(val))
   }
  },
  created() {},
  mounted() {
    this.fn();
    this.chosenAddressId=Number(this.$route.query.id)
  },
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang='less' scoped>
.order {
  width: 100%;
  height: 100%;
}
.box {
  padding-top: 80px;
}
</style>
